Copy AppleScript command, application command
The Copy command can function as an AppleScript command or an application command. The AppleScript command makes a copy of one or more values and stores it in one or more variables.The application command is a request to copy an object or objects. If the command includes a direct parameter, the Copy command makes a copy of one or more objects specified in the direct parameter and puts them in one or more new locations (if any are specified) or on the Clipboard (if no new location is specified).
If the command does not include a direct parameter, the Copy command makes a copy of the object or objects in the current selection and puts them
on the Clipboard. This is the same as choosing Copy from the Edit menu in
an application.As shown in the syntax definitions that follow,
put
andinto
are synonyms forcopy
andto
. When you compile a script,put
andinto
are automatically changed tocopy
andto
.APPLESCRIPT COMMAND SYNTAX
( copy | put ) expression ( to | into) variablePatternAPPLICATION COMMAND SYNTAX
( copy | put ) expression ( to | into) referencePattern ( copy | put ) [ referenceToObject ]PARAMETERS
- expression
- The expression whose value is to be assigned. If expression is a reference or a list or record of references, AppleScript gets the values of the objects specified by the references.
Class: Any class- variablePattern
- The name of the variable in which to store the value, or a list of variable patterns, or a record of variable patterns.
Class: Identifier, list, or record- referencePattern
- A reference to the location to which to copy expression, a list of reference patterns, or a record of reference patterns.
Class: Reference, list, or record
Default value: If you do not specify a new location, the object specified in the direct parameter is copied and put on the Clipboard.- referenceToObject
- A reference to the object or objects to be copied, or a list of reference patterns, or a record of reference patterns.
Class: Reference, list, or record
Default value: If this parameter is omitted, the object or objects in the current selection are copied and put on the Clipboard.RESULT
If the Copy command is used to create a variable, the result is the value that was stored in the variable. If the command is used to copy an object, the result
is a reference to the copied object; however, if the command does not include parameters, there is no result.
Class: VariesEXAMPLES
This example copies a string to the variablemyOccupation
:
copy "writer" to myOccupationThis example copies the value of a reference to the variablex
:
copy word 1 of front document of app "Scriptable Text Editor" to xThis example makes a copy of a word, and then inserts it at the beginning of the fourth paragraph:
tell application "Scriptable Text Editor" copy word 1 to beginning of paragraph 4 end tellThe next example copies a word to the Clipboard and then pastes it from the Clipboard to the insertion point after the tenth paragraph.
tell application "Scriptable Text Editor" select word 1 of document "Test" copy select insertion point after paragraph 10 of document "Test" paste end tellIn addition to copying a value to a single variable or object, you can copy patterns of values to patterns of variables. For example, this script copies
the position of the front window to a list of two variables:.
tell application "Scriptable Text Editor" copy position of front window to {x, y} end tellSince the Scriptable Text Editor returns position of front window as a list of two integers, the preceding example copies the first item in the list tox
and the second item in the list toy
.Patterns copied with the Copy command can also be more complex. Here's
an example:
set x to {8, 94133, {firstName:"John", lastName:"Chapman"}} copy x to {p, q, {lastName:r}} (* now p, q, and r have these values: p = 8 q = 94133 r = "Chapman" *)As this example demonstrates, the properties of a record need not be given in the same order and need not all be used when you copy a pattern to a pattern, as long as the patterns match.The use of the Copy command with patterns is similar to the use of the Set command with patterns. For information about the Set command, see page 116.
NOTES
For more information about using the Copy command to create or change the values of variables, see "Variables," which begins on page 150.If you use the Copy command without parameters and there is no selection to be copied, the application does not change the contents of the Clipboard.
When copying objects between applications via the Clipboard, you must
use the Activate command to make the receiving application active before attempting to paste from the Clipboard.ERRORS
Error
numberError message -1728 Can't get <reference>.
-10006 Can't set <destination> to <source>.